/**
 * Created By  醉美柳舞之众星捧月
 * @author Song
 * @date 2018/6/11 14:09
 */
import { Component, HttpException } from '@nestjs/common';

@Component()
export class UsersService {
  private users = [
    { id: 1, name: 'John Doe' },
    { id: 2, name: 'Alice Caeiro' },
    { id: 3, name: 'Who Knows' },
  ];

  getAllUsers() {
    return Promise.resolve(this.users);
  }

  getUser(id: number) {
    const user = this.users.find((user) => user.id === id);
    if (!user) {
      throw new HttpException('User not found', 404);
    }
    return Promise.resolve(user);
  }

  addUser(user) {
    this.users.push(user);
    return Promise.resolve();
  }
}